<?php

namespace App\Server;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class JwtServer
{
  // 加密
  public static function createToken($userId)
  {
    $key = "g_laravel_zw";
    $payload = array(
      "iat" => 1356999524,
      "nbf" => 1357000000,
      'user_id' => $userId
    );
    $jwt = JWT::encode($payload, $key, 'HS256');
    return $jwt;
  }
  // 解密
  public static function decodeToken($jwt)
  {
    $key = "g_laravel_zw";
    $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
    if ($decoded) {
      return $decoded;
    } else {
      return false;
    }
  }
}
